﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HomeAutomation
{
    class Device
    {
        //"17.FD.1E" may be broken :(
        public static InsteonDevice FRONT_SENSOR = new InsteonDevice("front sensor", "14.30.37");
        public static InsteonDevice DRIVEWAY_SENSOR = new InsteonDevice("driveway sensor", "14.36.83");
        public static InsteonDevice BACK_SENSOR = new InsteonDevice("back sensor", "14.33.2E");
        public static X10Device downstairsChime = new X10Device("E", 5);
        public static InsteonDevice FRONT_LIGHTS = new InsteonDevice("front lights", "18.C7.8F");
        public static InsteonDevice BACK_LIGHTS = new InsteonDevice("back lights", "17.BA.54");
        public static X10Device INSIDE_LIGHT = new X10Device("F", 7);

        public static HashSet<Device> ALL_SENSORS = new HashSet<Device> { Device.BACK_SENSOR, FRONT_SENSOR, Device.DRIVEWAY_SENSOR };
        public static HashSet<Device> FRONT_AND_BACK_SENSORS = new HashSet<Device> { FRONT_SENSOR, Device.BACK_SENSOR };
        public static HashSet<Device> FRONT_AND_DRIVEWAY_SENSORS = new HashSet<Device> { FRONT_SENSOR, Device.DRIVEWAY_SENSOR };


        private static Dictionary<string, InsteonDevice> insteonDevices = new Dictionary<string, InsteonDevice>()
        {
            { Device.DRIVEWAY_SENSOR.id(),  Device.DRIVEWAY_SENSOR},
            {FRONT_SENSOR.id(), FRONT_SENSOR},
            {Device.BACK_SENSOR.id(), Device.BACK_SENSOR},
            {FRONT_LIGHTS.id(), FRONT_LIGHTS},
            {BACK_LIGHTS.id(), BACK_LIGHTS}
        };


        public static Device getDevice_throwsException(string deviceId){
            if (insteonDevices.ContainsKey(deviceId))
            {
                return insteonDevices[deviceId];
            }
            else
            {
                throw new System.Exception("can't find a device with this id: " + deviceId);
            }
        }

    }
}
